﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using CCF20Model;
using WiseLink.RDS.Resource;

namespace CCF20Model
{
    public class DeviceCollection : ObservableCollection<Device>
    {
        private CCF20Entities ccf20Entities;
        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            Device device = null;
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:

                    device = (Device)e.NewItems[0];
                    device.InStockDate = DateTime.Now;
                    //we now only input the serial no. no need to input idc
                    //device.IDCSimNumber = "86"; 
                    device.IsRegistered = false;
                    device.DeviceStatus = DeviceStatus.InStock;
                    device.IsManual = true;
                    ccf20Entities.Devices.AddObject(device);
                    break;
                case NotifyCollectionChangedAction.Remove:

                    device = (Device)e.OldItems[0];
                    ccf20Entities.DeleteObject(device);
                    
                    break;
            }
            
            base.OnCollectionChanged(e);
        }

        public DeviceCollection(IQueryable<Device> devices, CCF20Entities context)
            : base(devices)
        {
            ccf20Entities = context;
        }

    }
}
